package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    //新增地址新增地址
    void insert(AddressBook addressBook);

    //根据id查询地址
    @Select("select *from address_book where user_id=#{id}")
    List<AddressBook> getAddress(Long id);

    //根据id查询地址-查询回显
    @Select("select *from address_book where id=#{id}")
    AddressBook getById(Long id);

    //修改地址
    void updateAddress(AddressBook addressBook);

    //删除地址
    @Select("delete from address_book where id=#{id}")
    void deleteAddress(Long id);

    //设置默认地址设置默认地址
    @Select("update address_book set is_default=#{isDefault} where id=#{id}")
    void setDefault(AddressBook addressBook);

    //根据id查询默认地址
    @Select("select *from address_book where user_id=#{currentId} and is_default=1")
    AddressBook getDefault(Long currentId);
}
